//
//  LCSongLyricsTableViewController.m
//  自适应TableView布局
//
//  Created by jiukuyinyue on 2017/10/12.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LCSongLyricsTableViewController.h"
#import "UITableView+SDAutoTableViewCellHeight.h"
#import "LCLrcLine.h"
#import "LCSongLyricsCell.h"
#import "JKSongsMessStatus.h"

#define cellID @"cellID"
#define SongLyricsCellID @"SongLyricsCellID"

@interface LCSongLyricsTableViewController ()<UIScrollViewDelegate>


@end

@implementation LCSongLyricsTableViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView.backgroundColor = [UIColor clearColor];/** 去除tableview 背景颜色 透明 */
    self.tableView.showsVerticalScrollIndicator = NO;/** 去除tableview 右侧滚动条 */
    self.tableView.separatorStyle = NO;/** 去除tableview cell线 */

    [self.tableView registerClass:[LCSongLyricsCell class] forCellReuseIdentifier:cellID];
    [self.tableView registerClass:[LCSongLyricsCell class] forCellReuseIdentifier:SongLyricsCellID];

}

#pragma mark - tableview datasourece and delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.lrc2Array.count > 0) {
        return self.lrc2Array.count;
    }
    return self.lrcArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.lrc2Array.count > 0) {
        
        LCSongLyricsCell *cell = [tableView dequeueReusableCellWithIdentifier:SongLyricsCellID];
        if (!cell) {
            cell = [[LCSongLyricsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SongLyricsCellID];
        }
        if (self.lrc2Array.count > indexPath.row) {
            cell.contentLabel.text = [NSString stringWithFormat:@"%@",self.lrc2Array[indexPath.row]];
        }
        cell.contentLabel.textAlignment = NSTextAlignmentCenter;
        cell.contentLabel.backgroundColor = [UIColor clearColor];
        cell.contentLabel.font = [UIFont systemFontOfSize:20];
        cell.contentLabel.textColor = [UIColor whiteColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor clearColor];//设置为透明色
        
        return cell;
    }
    LCSongLyricsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[LCSongLyricsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    if (_lrcArray.count > indexPath.row) {
        LCLrcLine * lrcLine = _lrcArray[indexPath.row];
        cell.contentLabel.text = [NSString stringWithFormat:@"%@",lrcLine.lrc];
    }
    if (self.currentRow == indexPath.row) {
        cell.contentLabel.textColor = [UIColor redColor];
    }else{
        cell.contentLabel.textColor = [UIColor whiteColor];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor clearColor];//设置为透明色
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [self cellHeightForIndexPath:indexPath cellContentViewWidth:[UIScreen mainScreen].bounds.size.width];

}

-(void)setLrcArray:(NSArray *)lrcArray{
    _lrcArray = lrcArray;
    [self.tableView reloadData];
}
- (void)setLrc2Array:(NSArray *)lrc2Array {
    _lrc2Array = lrc2Array;
    [self.tableView reloadData];
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    _isDragging = YES;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    _isDragging = NO;
}

@end
